package com.yegs.jindie.entity;


import com.alibaba.excel.metadata.BaseRowModel;
import com.yegs.jindie.service.UserConfigService;
import com.yegs.jindie.serviceImpl.UserConfigServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 *实体对象制造工厂
 */
@Component
public class ToFactory {

    @Autowired
    private UserConfigService userConfigService;

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Deprecated
    public DeliveryTO getDeliveryTO(Date date, String imei, String price, String reback) throws Exception {
        UserConfigTO userConfig = userConfigService.getUserConfig();
        if(userConfig == null){
            throw new Exception("获取初始化对象失败");
        }
        DeliveryTO deliveryTO = new DeliveryTO();
        deliveryTO.setCountry(userConfig.getCountry());
        deliveryTO.setProvince(userConfig.getProvince());
        deliveryTO.setCity(userConfig.getCity());
        deliveryTO.setSO_date(date);
        deliveryTO.setImei(imei);
        deliveryTO.setWhcode(userConfig.getWhcode());
        deliveryTO.setWhname(userConfig.getWhname());
        deliveryTO.setShopCode(userConfig.getShopcode());
        deliveryTO.setShopname(userConfig.getShopname());
        deliveryTO.setPrice(price);
        deliveryTO.setIndustrial(userConfig.getAgency_n());
        deliveryTO.setOnLine(userConfig.getLine_off());
        return  deliveryTO;
    }

    public DeliveryTO getDeliveryTO(Date date, String imei, String price, String reback, String productNumber) throws Exception {
        UserConfigTO userConfig = userConfigService.getUserConfig();
        if(userConfig == null){
            throw new Exception("获取初始化对象失败");
        }
        DeliveryTO deliveryTO = new DeliveryTO();
        deliveryTO.setCountry(userConfig.getCountry());
        deliveryTO.setProvince(userConfig.getProvince());
        deliveryTO.setCity(userConfig.getCity());
        deliveryTO.setSO_date(date);
        deliveryTO.setImei(imei);
        deliveryTO.setWhcode(userConfig.getWhcode());
        deliveryTO.setWhname(userConfig.getWhname());
        deliveryTO.setShopCode(userConfig.getShopcode());
        deliveryTO.setShopname(userConfig.getShopname());
        deliveryTO.setPrice(price);
        deliveryTO.setIndustrial(userConfig.getAgency_n());
        deliveryTO.setOnLine(userConfig.getLine_off());
        deliveryTO.setProductNumber(productNumber);
        return  deliveryTO;
    }

    @Deprecated
    public PurchaseTO getPurchaseTO(Date date,String imei,String price, String reback) throws Exception {
        UserConfigTO userConfig = userConfigService.getUserConfig();
        if(userConfig == null){
            throw new Exception("获取初始化对象失败");
        }
        PurchaseTO purchaseTO = new PurchaseTO();
        purchaseTO.setCountry(userConfig.getCountry());
        purchaseTO.setProvince(userConfig.getProvince());
        purchaseTO.setCity(userConfig.getCity());
        purchaseTO.setImei(imei);
        purchaseTO.setCustcode(userConfig.getCustomercode());
        purchaseTO.setCustname(userConfig.getCustomername());
        purchaseTO.setDate(date);
        purchaseTO.setWhcode(userConfig.getWhcode());
        purchaseTO.setWhname(userConfig.getWhname());
        purchaseTO.setPrice(price);
        purchaseTO.setIndustrial(userConfig.getAgency_n());
        purchaseTO.setOnLine(userConfig.getLine_off());
        purchaseTO.setReback(reback);
        return  purchaseTO;
    }

    public PurchaseTO getPurchaseTO(Date date,String imei,String price, String reback, String productName) throws Exception {
        UserConfigTO userConfig = userConfigService.getUserConfig();
        if(userConfig == null){
            throw new Exception("获取初始化对象失败");
        }
        PurchaseTO purchaseTO = new PurchaseTO();
        purchaseTO.setCountry(userConfig.getCountry());
        purchaseTO.setProvince(userConfig.getProvince());
        purchaseTO.setCity(userConfig.getCity());
        purchaseTO.setImei(imei);
        purchaseTO.setCustcode(userConfig.getCustomercode());
        purchaseTO.setCustname(userConfig.getCustomername());
        purchaseTO.setDate(date);
        purchaseTO.setWhcode(userConfig.getWhcode());
        purchaseTO.setWhname(userConfig.getWhname());
        purchaseTO.setPrice(price);
        purchaseTO.setIndustrial(userConfig.getAgency_n());
        purchaseTO.setOnLine(userConfig.getLine_off());
        purchaseTO.setReback(reback);
        purchaseTO.setProductNumber(productName);
        return  purchaseTO;
    }

    @Deprecated
    public InventoryTO getInventoryTO(Date date, String imei, String price) throws Exception {
        UserConfigTO userConfig = userConfigService.getUserConfig();
        if(userConfig == null){
            throw new Exception("获取初始化对象失败");
        }
        InventoryTO inventoryTO = new InventoryTO();
        inventoryTO.setImei(imei);
        inventoryTO.setDate(date);
        inventoryTO.setWhcode(userConfig.getWhcode());
        inventoryTO.setWhname(userConfig.getWhname());
        inventoryTO.setShopcode(userConfig.getShopcode());
        inventoryTO.setShopname(userConfig.getShopname());
        inventoryTO.setPrice(price);
        inventoryTO.setCountry(userConfig.getCountry());
        inventoryTO.setProvince(userConfig.getProvince());
        inventoryTO.setCity(userConfig.getCity());
        inventoryTO.setIndustrial(userConfig.getAgency_n());
        inventoryTO.setOnLine(userConfig.getLine_off());
        return  inventoryTO;
    }

    public InventoryTO getInventoryTO(Date date, String imei, String price, String productName) throws Exception {
        UserConfigTO userConfig = userConfigService.getUserConfig();
        if(userConfig == null){
            throw new Exception("获取初始化对象失败");
        }
        InventoryTO inventoryTO = new InventoryTO();
        inventoryTO.setImei(imei);
        inventoryTO.setDate(date);
        inventoryTO.setWhcode(userConfig.getWhcode());
        inventoryTO.setWhname(userConfig.getWhname());
        inventoryTO.setShopcode(userConfig.getShopcode());
        inventoryTO.setShopname(userConfig.getShopname());
        inventoryTO.setPrice(price);
        inventoryTO.setCountry(userConfig.getCountry());
        inventoryTO.setProvince(userConfig.getProvince());
        inventoryTO.setCity(userConfig.getCity());
        inventoryTO.setIndustrial(userConfig.getAgency_n());
        inventoryTO.setOnLine(userConfig.getLine_off());
        inventoryTO.setProductNumber(productName);
        return  inventoryTO;
    }

    public static String getDeliveryTxt(DeliveryTO delivery){
        return new StringBuilder()
                .append(delivery.getCountry()).append("\t")
                .append(delivery.getProvince()).append("\t")
                .append(delivery.getCity()).append("\t")
                .append(sdf.format(delivery.getSO_date())).append("\t")
                .append(delivery.getImei()).append("\t")
                .append(delivery.getWhcode()).append("\t")
                .append(delivery.getWhname()).append("\t")
                .append(delivery.getShopCode()).append("\t")
                .append(delivery.getShopname()).append("\t")
                .append(delivery.getPrice()).append("\t")
                .append("\t")
                .append("\t")
                .append("\n").toString();
//                .append(delivery.getIndustrial()).append("\t")
//                .append(delivery.getOnLine()).append("\t")
//                .append(delivery.getReback()).append("\n").toString();
    }

    public static String getPurchaseTOTxt(PurchaseTO purchaseTO){
        return new StringBuilder()
                .append(purchaseTO.getCountry()).append("\t")
                .append(purchaseTO.getProvince()).append("\t")
                .append(purchaseTO.getCity()).append("\t")
                .append(purchaseTO.getImei()).append("\t")
//                .append(purchaseTO.getCustname()).append("\t")
//                .append(purchaseTO.getCustcode()).append("\t")
                .append("\t")
                .append("\t")
                .append(sdf.format(purchaseTO.getDate())).append("\t")
                .append(purchaseTO.getWhname()).append("\t")
                .append(purchaseTO.getWhcode()).append("\t")
                .append(purchaseTO.getPrice()).append("\t")
                .append("\t")
                .append("\t")
                .append("\n").toString();
//                .append(delivery.getIndustrial()).append("\t")
//                .append(delivery.getOnLine()).append("\t")
//                .append(delivery.getReback()).append("\n").toString();
    }

    public static String getInventoryTOTxt(InventoryTO inventory){
        return new StringBuilder()
                .append(inventory.getImei()).append("\t")
                .append(sdf.format(inventory.getDate())).append("\t")
                .append(inventory.getWhcode()).append("\t")
                .append(inventory.getWhname()).append("\t")
                .append(inventory.getShopcode()).append("\t")
                .append(inventory.getShopname()).append("\t")
                .append(inventory.getPrice()).append("\t")
                .append(inventory.getCountry()).append("\t")
                .append(inventory.getProvince()).append("\t")
                .append(inventory.getCity()).append("\t")
                .append("\t")
                .append("\n").toString();
//                .append(delivery.getIndustrial()).append("\t")
//                .append(delivery.getOnLine()).append("\t").toString();
    }










    public String getString(ArrayList<BaseRowModel> list) throws InvocationTargetException, IllegalAccessException {
        Method[] methods = BaseRowModel.class.getDeclaredMethods();
        for(BaseRowModel base : list){
            for(Method meth : methods){
                if(meth.getName().contains("get")){
                    String str = (String) meth.invoke(base, null);
                    System.out.println(str);
                }
            }
        }
        return null;
    }
    public static void main(String args[]) throws InvocationTargetException, IllegalAccessException {
        ToFactory toFactory = new ToFactory();
        PurchaseTO purchaseTO = new PurchaseTO();
        System.out.println(purchaseTO);
    }
}
